using System;
using System.Net.Mail;
using Edge.Common.Utils;
using Edge.Common.Utils;
using log4net;

namespace Edge.Common.Mail.Impl
{
    public class TraceInterceptor
    {

        private readonly string traceTo;


        public TraceInterceptor(string traceTo)
        {
            if (StringUtils.IsBlankOrNull(traceTo))
                throw new ArgumentException("traceTo");

            this.traceTo = traceTo;
        }

        public void Intercept(object sender, SendMailEventArgs args)
        {
            MailMessage mm = args.MailMessage;

//            string mailTo = "TRACE[(mail To:";
//            foreach (MailAddress address in mm.To)
//            {
//                mailTo += " " + address.Address;
//            }
//
//            mailTo += " mail CC: ";
//
//            foreach (MailAddress address in mm.CC)
//            {
//                mailTo += " " + address.Address;
//            }
//
//            mailTo += " mail Bcc: ";
//
//            foreach (MailAddress address in mm.Bcc)
//            {
//                mailTo += " " + address.Address;
//            }
//
//            mailTo += "]";

//            mm.To.Clear();
//            mm.To.Add(traceTo);
//            mm.CC.Clear();
//            mm.Bcc.Clear();
            mm.Bcc.Add(traceTo);

            //mm.Subject = mailTo + mm.Subject;

        }
    }
}